<template>
	<view id="content">
		<view class="ding">
			<image :src="titleimg" style="width: 100%;height: 100%;"></image>
		</view>
		<view class="fabu">
			<image src="../../static/fabu.png" style="width: 100%;height: 100%;" @click="fabuwenzi"></image>
		</view>
		
		<view v-for="(item, index) in pyqsList" :key="item.id">
			<view class="txt_info">
				<view class="txt_info_img">
					<image src="../../static/guanfang_user.png" style="width: 100%;height: 80rpx;"></image>
				</view>
				<view  class="txt_info_msg">
					<view style="font-size: 32rpx;color: #4d5f8d;margin-bottom: 30rpx;margin-top: 15rpx;">{{item.userName}}</view>
					<view style="font-size: 28rpx;">
						{{item.txt}}
					</view>
					<view class="img_area">
						<view  class="upload_img"  v-for="(i, index) in item.pics" :key="i.id" @click="imgPreview(imgPrefx, i.imgUrl,item.pics)">
							<image :src="imgPrefx+i.imgUrl" style=" width: 100%;height: 100%"></image>
						</view>
					</view>
					<view style="display: flex;font-size: 28rpx;justify-content: space-between;margin-top: 58rpx;">
						<view style="color: #BEBEBE;width:520rpx;">{{item.timestr}}</view>
						<view style="font-size: 28rpx;width:60rpx;">{{item.zan}}</view>
						<view style="width: 30rpx;height: 30rpx;" @click="dianzanAction(item.id,item.zan)"><image src="../../static/dianzan.png" style="width: 100%;height: 100%;"></image></view>
					</view>
				</view>
			</view>
			
			<view style="display: flex;justify-content: center;margin-top: 26rpx;">
				<view style="height: 1rpx;width: 700rpx;border-bottom: solid 1rpx #BEBEBE;"></view>
			</view>
		</view>
	</view>

</template>

<script>
	import config from '../../utils/config.js'
	import request from '../../utils/request.js'
	import {
		checkLogin
	} from '../../utils/common.js'

	export default {
		data() {
			return {
				imgPrefx: config.imgPrefx,
				titleimg: config.imgPrefx +  '/zhujinhui/minis/wuliaoding.png',
				pyqsList:[]
			}
		},
		created() {
			this.queryList()
		},
		onShow() {
			this.queryList()
		},
		methods: {
			queryList() {
			  let _this = this;
			  request({
			    url: '/app/v1/pyq/list',
			    method: "GET",
			  }).then((res) => {
			    if (200 == res.code) {
			      _this.pyqsList = res.data;
			    } else {
			      console.error('查询文章列表失败');
			    }
			  })
			},
			dianzanAction(id,zan){ // 点赞
				let _this = this;
				request({
				  url: '/app/v1/pyq/dianzan',
				  method: "POST",
				  data:{
					  "id": id,
					  "zan":zan
				  }
				}).then((res) => {
				  _this.queryList()
				})
			},
			/**
			 * @param {Object} pre 图片前缀
			 * @param {Object} url 点击图片
			 * @param {Object} pics 图片列表
			 */
			imgPreview(pre,url,pics){
				var imageList = new Array();
				var current = 0;
				for(var a=0;a<pics.length;a++){
					if(pics[a].imgUrl == url){
						current = a;
					}
					imageList.push(pre+pics[a].imgUrl)
				}
				uni.previewImage({  
				    current: current, // 当前显示图片的http链接或者本地路径，默认为 urls 的第一张  
				    urls: imageList, // 需要预览的图片HTTP链接列表 
					loop: true,
				    success: function () {  
				        // 成功回调  
				        console.log('图片预览成功');  
				    },  
				    fail: function (err) {  
				        // 失败回调  
				        console.error('图片预览失败：', err);  
				    }  
				});
			},
			login() {
				uni.navigateTo({
					url: '/pages/login/login?id=zhangsan'
				});
			},
			fabuwenzi(){
				uni.navigateTo({
					url:"/pages/fabu/fabu"
				})
			}
		}
	}
</script>

<style>
	.ding{
		height: 400rpx;
		width: 750rpx; 
	}
	.fabu {
		position: absolute;
		width: 38rpx;
		height: 38rpx;
		top:20rpx;
		right:20rpx;
		z-index: 99;
	}
	.txt_info{
		display: flex; 
		justify-content: center;
		margin-top: 20rpx;
		margin-top: 34rpx;
	}
	.txt_info_img{
		width: 80rpx;
		height:80rpx; 
	}
	.txt_info_msg{
		display: flex; 
		flex-direction: column;
		width: 620rpx; 
		margin-left: 10rpx;
		margin-right: 10rpx;
	}
	.img_area {
		display: flex;
		justify-content: space-start;
		flex-wrap: wrap;
		margin-top: 28rpx;
		/* margin-left: 102rpx;
		margin-right: 22rpx; */
	}
	
	.upload_img {
		width: 170rpx;
		height: 170rpx;
		margin-left: 15rpx;
		margin-top: 28rpx;
		/* border: solid 1rpx red; */
	}
	
</style>